package eu.jk.performance.buffer;

import java.util.Hashtable;

public class BufferFactory<T> {

	private static Hashtable<String, BufferPool<Object>> poolMap = new Hashtable<String, BufferPool<Object>>();

	public BufferPool<T> newBufferPool(int size, boolean sync) {
		if (sync)
			return new BufferPoolSync<T>(size);
		return new BufferPoolNosync<T>(size);
	}
	
	@SuppressWarnings("unchecked")
	public BufferPool<T> getById(String id){
		return (BufferPool<T>) poolMap.get(id);
	}
	
	@SuppressWarnings("unchecked")
	public BufferPool<T> newBufferPool(String id,int size, boolean sync){
		if(poolMap.containsKey(id))
			return getById(id);
		BufferPool<T> bp=newBufferPool(size, sync);
		poolMap.put(id, (BufferPool<Object>) bp);
		return bp;
	}
}
